﻿using LinkGame.Models;
using System.ComponentModel;

namespace LinkGame
{
    internal partial class FrmDiag : Form
    {

        #region Public Constructors

        public FrmDiag()
        {
            InitializeComponent();
        }

        #endregion Public Constructors

        #region Public Events

        public event EventHandler<ResolutionPathSelectedEventArgs>? ResolutionPathSelected;

        #endregion Public Events

        #region Public Methods

        public void UpdatePossiblePaths(IEnumerable<ResolutionPath> possiblePaths)
        {
            lst.Items.Clear();
            foreach (var resolutionPath in possiblePaths)
            {
                lst.Items.Add(resolutionPath);
            }
        }

        #endregion Public Methods

        #region Protected Methods

        protected override void OnClosing(CancelEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
            base.OnClosing(e);
        }

        #endregion Protected Methods

        #region Private Methods

        private void chk_CheckedChanged(object sender, EventArgs e)
        {
            if (lst.SelectedItem != null)
            {
                var selectedPath = (ResolutionPath)lst.SelectedItem;
                ResolutionPathSelected?.Invoke(this, new(chk.Checked, selectedPath));
            }
            else
            {
                ResolutionPathSelected?.Invoke(this, new(chk.Checked, null));
            }
        }

        private void lst_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedPath = (ResolutionPath?)lst.SelectedItem;
            if (selectedPath != null)
            {
                ResolutionPathSelected?.Invoke(this, new(chk.Checked, selectedPath));
            }
        }

        #endregion Private Methods
    }
}
